package games.tankwars.behaviors;

import java.util.Set;

import games.tankwars.Level;
import games.tankwars.entities.Bullet;
import games.tankwars.entities.MazeElement;
import vooga.behaviors.MoveBehavior;
import vooga.entities.Entity;
import vooga.geom.DoubleDimension;
import vooga.geom.Vector;

public class Launch extends vooga.behaviors.AbstractBehavior
{
    private games.tankwars.entities.Tank myTank;
    private vooga.core.AbstractLevel myLevel;
    private int myTimer;
    private boolean onTail;
    private boolean missileInMotion;
        
    public Launch (games.tankwars.entities.Tank tank, games.tankwars.Level level)
    {
    	myTimer=0;
        myTank = tank;
        myLevel=level;
        onTail=false;
        missileInMotion=false;
    }

	@Override
	public void step(Entity target) {
		myTimer++;
		if (myTimer%myLevel.getFrameRate()*1000000 == 0)
		{
			if (myTank.isVisible() && !missileInMotion)
			{
				{
					MazeElement missile = new MazeElement (new java.awt.geom.Point2D.Double (target.getCenterX(),target.getCenterY()), new DoubleDimension (5,2), false);
					missile.addBehavior(new MoveBehavior());
					missile.addBehavior(new games.tankwars.behaviors.IntersectAndRemove(missile.getVelocity(), myLevel.getEntities("maze"),myLevel));
					missile.addBehavior(new games.tankwars.behaviors.IntersectAndRemoveBoth(missile.getVelocity(),myTank,myLevel));
					missile.addBehavior(new games.tankwars.behaviors.FollowPrecise(myTank,myLevel));
					myLevel.addEntity(missile);
					missileInMotion=true;
				}
			}
		}
	}
}
